package Logic;

import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;

import Config.GeneralsConfig;
import FileStatus.Property;

public class TaskMaintain {

	public static void writeCON(String Mac) throws IOException {
		Property.writeProperty(Mac);
		FileWriter tmp = new FileWriter(Mac + "/Order/"
				+ System.currentTimeMillis());
		tmp.write("CON:oracle:" + GeneralsConfig.stringDataBaseUrl + ":"
				+ GeneralsConfig.stringDataBaseUsername + ":"
				+ GeneralsConfig.stringDataBasePassword);
		tmp.close();
	}

	public static void generateTask(ArrayList<String> src, String tablename,
			String Mac_ID, String Unique_ID) throws IOException {
		String needSQL = "";
		tablename = tablename.replaceAll(" ", "").replaceAll("	", "");
		for (String tmp : src) {
			String tmps[] = tmp.split(" ");
			needSQL += (" " + tmps[0] + ",");
		}

		if (needSQL.length() != 0) {
			needSQL = needSQL.substring(0, needSQL.length() - 1);
			needSQL = "select " + needSQL + " from " + tablename;
		}

		FileWriter tmp = new FileWriter(Mac_ID + "/Order/"
				+ System.currentTimeMillis());
		tmp.write("SQL:" + Unique_ID + ":" + needSQL);
		tmp.close();

	}

	public static void writeVAL(String Mac, String valueName, String value)
			throws IOException {
		FileWriter tmp = new FileWriter(Mac + "/Order/"
				+ System.currentTimeMillis());
		tmp.write("VAL:" + valueName + ":" + value);
		tmp.close();
	}
}
